//
//  KongWfindHospitalTableViewCell.m
//  LoveOfPet
//
//  Created by dllo on 15/11/17.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "KongWfindHospitalTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
#define kHeight     [UIScreen mainScreen].bounds.size.height / 667
#define kWidth      [UIScreen mainScreen].bounds.size.width / 375
@interface KongWfindHospitalTableViewCell ()
@property (retain, nonatomic) UIView *backView;

@property (retain, nonatomic) UIImageView *scoreImg;

@property (retain, nonatomic) UIImageView *distanceImg;
@end
@implementation KongWfindHospitalTableViewCell
-(void)dealloc
{
    [_img release];
    [_nameLabel release];
    [_scoreLabel release];
    [_distanceLabel release];
    [_addressLabel release];
    [_backView release];
    [_scoreImg release];
    [_distanceImg release];
    [super dealloc];
}
-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubView];
    }
    return self;
}

-(void)creatSubView
{
    self.backView = [[UIView alloc] init];
    self.backView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.backView];
    [self.backView release];
    
    self.img = [[UIImageView alloc] init];
    [self.backView addSubview:self.img];
    [self.img release];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.backView addSubview:self.nameLabel];
    [self.nameLabel release];
    
    self.scoreImg = [[UIImageView alloc] init];
    [self.backView addSubview:self.scoreImg];
    [self.scoreImg release];
    
    self.scoreLabel = [[UILabel alloc] init];
    [self.backView addSubview:self.scoreLabel];
    [self.scoreLabel release];
    
    self.distanceLabel = [[UILabel alloc] init];
    [self.backView addSubview:self.distanceLabel];
    [self.distanceLabel release];
    
    self.addressLabel = [[UILabel alloc] init];
    [self.backView addSubview:self.addressLabel];
    [self.addressLabel release];
    
    self.distanceImg = [[UIImageView alloc] init];
    [self.backView addSubview:self.distanceImg];
    [self.distanceImg release];

}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.backView.frame = CGRectMake(0, kHeight * 5, self.contentView.frame.size.width, self.contentView.frame.size.height - kHeight * 5);
    
    self.img.frame = CGRectMake(kWidth * 10, kHeight * 10, 70, 70);
    
    self.nameLabel.frame = CGRectMake(self.img.frame.origin.x + self.img.frame.size.width + 20, self.img.frame.origin.y, kWidth * 120, kHeight * 20);
    
    self.addressLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height + kHeight * 10, kWidth * 260, kWidth * 20);
    
    self.scoreImg.frame = CGRectMake(self.addressLabel.frame.origin.x, self.addressLabel.frame.origin.y + self.addressLabel.frame.size.height + kHeight * 10, kWidth * 20, kHeight * 20);
    
    self.scoreLabel.frame = CGRectMake(self.scoreImg.frame.origin.x + self.scoreImg.frame.size.width + kWidth * 5, self.scoreImg.frame.origin.y, kWidth * 30, self.scoreImg.frame.size.height);
    
    self.distanceImg.frame = CGRectMake(self.scoreLabel.frame.origin.x + self.scoreLabel.frame.size.width + kWidth * 50, self.scoreLabel.frame.origin.y, self.scoreImg.frame.size.width, self.scoreImg.frame.size.height);
    
    self.distanceLabel.frame = CGRectMake(self.distanceImg.frame.origin.x + self.distanceImg.frame.size.width + kWidth * 5, self.distanceImg.frame.origin.y, kWidth * 200, self.distanceImg.frame.size.height);
    
}

-(void)setFindHospital:(KongWFindHospitanModel *)findHospital
{
    if (_findHospital != findHospital) {
        [_findHospital release];
        _findHospital = [findHospital retain];
    }
    [self.img sd_setImageWithURL:[NSURL URLWithString:findHospital.photo_url]];
    NSString *name = [findHospital.name stringByReplacingOccurrencesOfString:@"<font color=\"#00a0e9\">" withString:@""];
    name =  [name stringByReplacingOccurrencesOfString:@"</font>" withString:@""];
    self.nameLabel.text = name;
    self.addressLabel.text = findHospital.address;
    self.scoreImg.image = [UIImage imageNamed:@"KONGWScoreStar"];
    self.scoreLabel.text = [NSString stringWithFormat:@"%ld", findHospital.avg_rating];
    self.distanceImg.image = [UIImage imageNamed:@"KongWiconfont-position"];
    self.distanceLabel.text = [NSString stringWithFormat:@"%.2fkm", findHospital.distance / 1000];
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
